// pages/new_inter/hotel_list/hotel_list.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {

    //价格
    price_arr: [
      {
        id: 0,
        Title: '全部',
      },
      {
        id: 1,
        Title: '0-1000',
      },
      {
        id: 2,
        Title: '1000-2000',
      },
      {
        id: 3,
        Title: '2000-3000',
      },
      {
        id: 4,
        Title: '3000-5000',
      },
      {
        id: 5,
        Title: '5000以上',
      },

    ],
    //活动
    area_arr: [
      {
        id: 0,
        Title: '全部',
      },
      {
        id: 1,
        Title: '普通商品',
      },
      {
        id: 2,
        Title: '满减',
      },
      {
        id: 3,
        Title: '秒杀',
      },
      {
        id: 4,
        Title: '拼团',
      },
      // {
      //   id: 5,
      //   Title: '积分商城',
      // },

    ],
   
    num: '4',
    name:'',
    price:'', 
    sort:"",
    act:'',
    c1:'',
    hostUrl: app.globalData.hostUrl,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      name: options.name,
      c1: options.c1,
      act: options.act
    })
    this.goods_list();
  },
  goods_list: function() {
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Index/goods_list',
      data: {
        // opt: 'getBanner',
        // area: that.data.area
        name:that.data.name,
        c1: that.data.c1,
        price: that.data.price,
        sort: that.data.sort,
        act: that.data.act,

      },
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        // console.log(res)
        if (res.data != null) {

          // var adv = res.data.adv[0];
          // for (var i = 0, len = adv.length; i < 2; ++i) {
          //   var desc = that.delHtmlTag(res.data.adv[0][i].desc)
          //   res.data.adv[0][i].desc = desc;
          // }
          that.setData({
            list: res.data,
          })

          // console.log(that.data.info, '过滤后')
        }
      }
    })
  },
  //分类选择
  bindFenleiChange: function(e) {
    var flindex = e.detail.value;

    var Category1 = this.data.list['Category1'];
    this.setData({
      c1: Category1[flindex]['ID'],
      flindex: e.detail.value
    })
    console.log('picker发送选择改变，携带值为', this.data.c1)

    this.goods_list();
  },
  // 活动选择
  bindHuodongChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var hdindex = e.detail.value;
    var area_arr = this.data.area_arr;
    this.setData({
      act: area_arr[hdindex]['id'],
      hdindex: e.detail.value
    })
    this.goods_list();
  },
   // 价格选择
  bindJiageChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var jgindex = e.detail.value;
    var price_arr = this.data.price_arr;
    this.setData({
      act: price_arr[jgindex]['id'],
      hdindex: e.detail.value
    })
    this.goods_list();
  },
  zonghe: function () {
    this.setData({
      sort:'0'
    })
    this.goods_list();
  },
  sales: function () {
    this.setData({
      sort: 1
    })
    this.goods_list();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  index: function () {
    wx.reLaunch({
      url: '/pages/index/index'
    })
  },
})